#include "window.hh"

#include <cassert>

#include <GL/glew.h>

unsigned int Window::W_WIDTH = 0;
unsigned int Window::W_HEIGHT = 0;

Window::Window (unsigned width, unsigned height) :
  width_ (width),
  height_ (height),
  screen_ (0),
  fovy_ (70),
  ratio_ ((float) width / (float) height),
  near_ (1),
  far_ (1000)
{
  W_WIDTH = width;
  W_HEIGHT = height;

  assert (SDL_Init (SDL_INIT_VIDEO) != -1);

  screen_ = SDL_SetVideoMode (width, height, 32, SDL_HWSURFACE |
			      SDL_GL_DOUBLEBUFFER | SDL_OPENGL);
  assert (screen_);

  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();

  gluPerspective (fovy_, ratio_, near_, far_);

  glEnable (GL_DEPTH_TEST);

  // Make things dirty with triangle_strip displaying
  // glEnable (GL_CULL_FACE);
  // glCullFace(GL_BACK);
  glEnable (GL_TEXTURE_2D);
  glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);

  SDL_WM_SetCaption ("booby", 0);
}

Window::~Window ()
{
  SDL_FreeSurface (screen_);
  SDL_Quit ();
}

SDL_Surface*
Window::screen_get ()
{
  return screen_;
}

unsigned
Window::width_get ()
{
  return width_;
}

unsigned
Window::height_get ()
{
  return height_;
}
